<%@ page language="java" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>地图应用示例</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<script src="http://ditu.google.cn/maps?file=api&amp;v=2&amp;key=ABQIAAAARqWWAJSskRjPZ84WYabNxhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQASyI3IocIBqKmrKrhVie-DyiFBg&sensor=true_or_false" type="text/javascript"></script>
		<script type="text/javascript">
var map;
var geocoder;
var address;

    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map_canvas"));
        //map.setMapType(G_SATELLITE_MAP);
        //map.setZoom(13);
        map.setCenter(new GLatLng(39.9493, 116.3975), 13);
        /*
        map.openInfoWindow(map.getCenter(),
                   document.createTextNode("Hello, world"));
          */
          
/*          
GEvent.addListener(map,"click", function(overlay, latlng) {     
  if (latlng) { 
    var myHtml = "GPoint 为: " + map.fromLatLngToDivPixel(latlng) + ",缩放级别:" + map.getZoom();
    map.openInfoWindow(latlng, myHtml);
  }
});
*/
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());         
map.addControl(new GOverviewMapControl ());
map.addControl(new GMapTypeControl());                   
GEvent.addListener(map, "click", getAddress);

        var bounds = map.getBounds();
  		var southWest = bounds.getSouthWest();
  		var northEast = bounds.getNorthEast();
  		var lngSpan = northEast.lng() - southWest.lng();
  		var latSpan = northEast.lat() - southWest.lat();
  		for (var i = 0; i < 10; i++) {
    		var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
        	southWest.lng() + lngSpan * Math.random());
    		map.addOverlay(new GMarker(point));
  		}
  		geocoder = new GClientGeocoder();
      }
      
    }
    
	
	
	function getAddress(overlay, latlng) {
  if (latlng != null) {
    address = latlng;
    geocoder.getLocations(latlng, showAddress);
  }
}

function showAddress(response) {
  map.clearOverlays();
  if (!response || response.Status.code != 200) {
    alert("Status Code:" + response.Status.code);
  } else {
    place = response.Placemark[0];
    point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
    marker = new GMarker(point);
    map.addOverlay(marker);
    marker.openInfoWindowHtml(
        '<b>orig latlng:</b>' + response.name + '<br/>' + 
        '<b>latlng:</b>' + place.Point.coordinates[0] + "," + place.Point.coordinates[1] + '<br>' +
        '<b>Status Code:</b>' + response.Status.code + '<br>' +
        '<b>Status Request:</b>' + response.Status.request + '<br>' +
        '<b>Address:</b>' + place.address + '<br>' +
        '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Locality:</b>' + place.AddressDetails.Accuracy + '<br>' +
        '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  }
}
	
    </script>

	</head>

	<body onload="initialize()" onunload="GUnload()">
		<div id="map_canvas" style="width: 1500px; height: 800px"></div>
	</body>

</html>
